home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- import logging
- from cStringIO import StringIO
- from cPickle import Unpickler, Pickler
- from pickle import PicklingError
- from ZODB.POSException import ConflictError
- from ZODB.loglevels import BLATHER
- logger = logging.getLogger('ZODB.ConflictResolution')
- ResolvedSerial = 'rs'
-
- class BadClassName(Exception):
- pass
-
- _class_cache = { }
- _class_cache_get = _class_cache.get
-
- def find_global(*args):
- cls = _class_cache_get(args, 0)
- if cls == 0:
-
- try:
- module = __import__(args[0], { }, { }, [
- 'cluck'])
- except ImportError:
- cls = 1
-
- cls = getattr(module, args[1], 1)
- _class_cache[args] = cls
- if cls == 1:
- logger.log(BLATHER, 'Unable to load class', exc_info = True)
-
-
- if cls == 1:
- raise BadClassName(*args)
-
- return cls
-
-
- def state(self, oid, serial, prfactory, p = ''):
- if not p:
- pass
- p = self.loadSerial(oid, serial)
- file = StringIO(p)
- unpickler = Unpickler(file)
- unpickler.find_global = find_global
- unpickler.persistent_load = prfactory.persistent_load
- unpickler.load()
- return unpickler.load()
-
-
- class PersistentReference:
-
- def __repr__(self):
- return 'PR(%s %s)' % (id(self), self.data)
-
-
- def __getstate__(self):
- raise PicklingError("Can't pickle PersistentReference")
-
-
-
- class PersistentReferenceFactory:
- data = None
-
- def persistent_load(self, oid):
- if self.data is None:
- self.data = { }
-
- r = self.data.get(oid, None)
- if r is None:
- r = PersistentReference()
- r.data = oid
- self.data[oid] = r
-
- return r
-
-
-
- def persistent_id(object):
- if getattr(object, '__class__', 0) is not PersistentReference:
- return None
-
- return object.data
-
- _unresolvable = { }
-
- def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle, committedData = ''):
-
- try:
- prfactory = PersistentReferenceFactory()
- file = StringIO(newpickle)
- unpickler = Unpickler(file)
- unpickler.find_global = find_global
- unpickler.persistent_load = prfactory.persistent_load
- meta = unpickler.load()
- if isinstance(meta, tuple):
- klass = meta[0]
- if not meta[1]:
- pass
- newargs = ()
- if isinstance(klass, tuple):
- klass = find_global(*klass)
-
- else:
- klass = meta
- newargs = ()
- if klass in _unresolvable:
- return None
-
- newstate = unpickler.load()
- inst = klass.__new__(klass, *newargs)
-
- try:
- resolve = inst._p_resolveConflict
- except AttributeError:
- _unresolvable[klass] = 1
- return None
-
- old = state(self, oid, oldSerial, prfactory)
- committed = state(self, oid, committedSerial, prfactory, committedData)
- resolved = resolve(old, committed, newstate)
- file = StringIO()
- pickler = Pickler(file, 1)
- pickler.persistent_id = persistent_id
- pickler.dump(meta)
- pickler.dump(resolved)
- return file.getvalue(1)
- except (ConflictError, BadClassName):
- return None
- except:
- logger.error('Unexpected error', exc_info = True)
- return None
-
-
-
- class ConflictResolvingStorage:
- '''Mix-in class that provides conflict resolution handling for storages'''
- tryToResolveConflict = tryToResolveConflict
-
-